package cn.hc.tool.exec.bean;

import lombok.Data;

import java.io.Serializable;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/9/24 19:44
 */
@Data
public class HcResult<T> implements Serializable {

    private static final long serialVersionUID = -3106688399199937944L;

    /**
     * 错误码
     */
    private int code = 200;
    /**
     * 错误描述
     */
    private String message = "";

    private T data;

    private boolean success = false;

    /**
     * 成功
     */
    public static <T> HcResult<T> success(T data) {
        HcResult<T> result = new HcResult<T>();
        result.setCode(200);
        result.setSuccess(true);
        result.setMessage("success");
        result.setData(data);

        return result;
    }

    /**
     * 失败
     */
    public static <T> HcResult<T> fail(T data, String message) {
        HcResult<T> result = new HcResult<T>();
        result.setCode(-1);
        result.setSuccess(false);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    /**
     * 失败
     */
    public static <T> HcResult<T> fail(String message) {
        HcResult<T> result = new HcResult<T>();
        result.setCode(-1);
        result.setSuccess(false);
        result.setMessage(message);
        result.setData(null);
        return result;
    }

}
